package controller;

import java.awt.GridBagLayout;
import java.awt.event.*;
import javax.swing.*;

import view.FieldView;

import model.Field;
import model.Simulator;
import controller.JTextFieldNumbersOnly;

/**
 * The class ParamController extends AbstractController
 * @author Brendan
 *
 */
public class ParamController extends AbstractController implements ActionListener {
	private static final long serialVersionUID = -3762097023651830639L;
	private JTextField depthTextField;
    private JTextField widthTextField;
    private JButton startButton;
    private JButton resetButton;
        
    /**
     * Create a new ParamController using the simulator
     * @param simulator
     */
    public ParamController(Simulator simulator)
    {
        super(simulator);
        
        depthTextField = new JTextFieldNumbersOnly("40");
        this.add(depthTextField);
        
        widthTextField = new JTextFieldNumbersOnly("40");
        this.add(widthTextField);
        
        startButton = new JButton("New Simulation");
        this.add(startButton);
        startButton.addActionListener(this);
        
        resetButton = new JButton("Reset");
        this.add(resetButton);
        resetButton.addActionListener(this);
    }

    /**
     * overrides the actionPerformed method
     * @param e
     * @override
     */
    public void actionPerformed(ActionEvent e) {           
    	if(simulator.isReady()) {    
			if (e.getSource()==startButton) {
	        	int depth = Integer.parseInt(depthTextField.getText());
	        	int width = Integer.parseInt(widthTextField.getText());   
	    		simulator.setField(new Field(depth, width));
	    		simulator.reset();
	        }
	        if (e.getSource()==resetButton) {
	        	simulator.reset();
	        }
    	}
    	else {
    		JOptionPane.showMessageDialog(this,
        		    "Sla de settings eerst op!",
        		    "Save settings warning",
        		    JOptionPane.WARNING_MESSAGE);
    	}
    }
}
